@isTest
private class AccountNewOverrideControllerTest {
	
	private static ID curAccId;
	private static ID curOppId;
	
	private static string recordTypeAASMasterClient   = RecordTypeHelper.GetRecordTypeId('Account', 'AAS Master Client');
    private static string recordTypeAASAgency         = RecordTypeHelper.GetRecordTypeId('Account', 'AAS Agency');
    private static string recordTypeAASSalesAccount   = RecordTypeHelper.GetRecordTypeId('Account', 'AAS Sales Account');
    private static string recordTypeAASIngenio	      = RecordTypeHelper.GetRecordTypeId('Account', 'Agency Managed Customer - Ingenio');
    private static string recordTypeLocalAdvertiser   = RecordTypeHelper.GetRecordTypeId('Account', 'Local OOR Customer');
    
	private static User userAAS;
	private static User userLocal;
	
	private static void init(){
		  string[] profileList = new String [] {'AAS Operations Team','Advanced Ad Solutions (Delegated Admin)','Advanced Ad Solutions (Client Services)','SFA OOR Sales Operations'};
		  list<Profile> pfs = [select ID, Name from Profile where Name  IN :profileList];
		  
	      //Create a map between the Profile Name and Id for easy retrieval
       	  Map<String,String> profiles = new Map<String,String>{};
     	  for(Profile pf: pfs)
        	profiles.put(pf.Name,pf.Id);
     
		  
	      userAAS = new User();
	      userAAS.UserName = 'AASUser@att.com';
	      userAAS.LastName = 'Test User1';
	      userAAS.Email = 'test1@attinteractive.com';
	      userAAS.Alias = 'testAAS' ;
	      userAAS.CommunityNickname = 'xyaz_1234556';
	      userAAS.TimeZoneSidKey = 'America/Los_Angeles';
	      userAAS.LocaleSidKey = 'en_US';
	      userAAS.EmailEncodingKey = 'UTF-8';
	      userAAS.ProfileId = profiles.get('AAS Operations Team');	      
	      userAAS.LanguageLocaleKey = 'en_US';
	      userAAS.IsActive = true;
	      insert userAAS;
		
	      userLocal = new User();
	      userLocal.UserName = 'LocalUser@att.com';
	      userLocal.LastName = 'Test User2';
	      userLocal.Email = 'test2@attinteractive.com';
	      userLocal.Alias = 'testLOC' ;
	      userLocal.CommunityNickname = 'xyaz_1234557';
	      userLocal.TimeZoneSidKey = 'America/Los_Angeles';
	      userLocal.LocaleSidKey = 'en_US';
	      userLocal.EmailEncodingKey = 'UTF-8';
	      userLocal.ProfileId = profiles.get('SFA OOR Sales Operations');	      
	      userLocal.LanguageLocaleKey = 'en_US';
	      userLocal.IsActive = true;
	      insert userLocal;

	    
	}
	
	 public static testMethod void testLocalAdvertiserAccount() {
		init();
				
		System.runAs(userLocal)
    	{
			PageReference pageRef = Page.AccountNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeLocalAdvertiser);
			Account acc = new Account();
			ApexPages.StandardController sc = new ApexPages.StandardController(acc);
			
			AccountNewOverrideController controller = new AccountNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirected to standard create account page
			System.assert(nextPage.getUrl().Contains('/001/e'));
			
    	}
	}
	public static testMethod void testAASMasterClientAccount() {
		init();
				
		System.runAs(userAAS)
    	{
			PageReference pageRef = Page.AccountNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeAASMasterClient);
			Account acc = new Account();
			ApexPages.StandardController sc = new ApexPages.StandardController(acc);
			
			AccountNewOverrideController controller = new AccountNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirected to standard create account page
			System.assert(nextPage.getUrl().Contains('/001/e'));
			
    	}
	}

  	public static testMethod void testAASIngenioAccount() {
		init();
				
		System.runAs(userAAS)
    	{
			PageReference pageRef = Page.AccountNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeAASIngenio);
			Account acc = new Account();
			ApexPages.StandardController sc = new ApexPages.StandardController(acc);
			
			AccountNewOverrideController controller = new AccountNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirect to standard error page 
			System.assert(nextPage.getUrl().Contains('/apex/feedback'));
			
    	}
  	}	

	 	
  	public static testMethod void testAASAgencyAccount() {
		init();
				
		System.runAs(userAAS)
    	{
			PageReference pageRef = Page.AccountNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeAASAgency);
			Account acc = new Account();
			ApexPages.StandardController sc = new ApexPages.StandardController(acc);
			
			AccountNewOverrideController controller = new AccountNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirected to standard create account page
			System.assert(nextPage.getUrl().Contains('/001/e'));
			
    	}
  	}	
  	
    public static testMethod void testAASAccount() {
		init();
				
		System.runAs(userAAS)
    	{
			PageReference pageRef = Page.AccountNewOverride;
			Test.setCurrentPage(pageRef);
			
			//add recordtype parameters to URL
			ApexPages.currentPage().getParameters().put('RecordType', recordTypeAASSalesAccount);
			Account acc = new Account();
			ApexPages.StandardController sc = new ApexPages.StandardController(acc);
			
			AccountNewOverrideController controller = new AccountNewOverrideController(sc);			
			PageReference nextPage = controller.doRedirect();
			system.Debug('url->'  + nextPage.getUrl());
			
			//redirected to standard create account page
			System.assert(nextPage.getUrl().Contains('/apex/selectmasterclient'));
			
    	}	
    	
	}
	
		

}